{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "#注释ctrl+?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAEiFJREFUeJzt3X+MlVedx/H3dwHbsUantGhgwIVGghqNSyUulc1mU1yxXSPEbbM1RolLwj/dtVqDwu4fzf5lDcaqyaaRWN26Mf7YSiipjayB+sduIrsgprQiW6xuYUBL107d6LgCfvePe6YMdGDunbkzl3ue9yuZzH3Ocy5zzn2Gzzz3PM+5JzITSVK9/qDXDZAkzSyDXpIqZ9BLUuUMekmqnEEvSZUz6CWpcga9JFXOoJekyhn0klS5ub1uAMD111+fS5cu7XUzJKmvHDx48LnMXDBZvSsi6JcuXcqBAwd63QxJ6isR8d/t1HPoRpIqZ9BLUuUMekmqnEEvSZUz6CWpclfEXTdSTXYdGmb7nqOcHBll0eAAW9atYMPKoV43Sw1m0EtdtOvQMNt2Hmb0zDkAhkdG2bbzMIBhr55x6Ebqou17jr4Y8mNGz5xj+56jPWqRZNBLXXVyZLSjcmk2GPRSFy0aHOioXJoNBr3URVvWrWBg3pwLygbmzWHLuhU9apHkxVipq8YuuHrXja4kBr3UZRtWDhnsuqI4dCNJlTPoJalyBr0kVc6gl6TKGfSSVDmDXpIqZ9BLUuUMekmqnEEvSZUz6CWpcga9JFXOoJekyhn0klQ5g16SKmfQS1LlDHpJqpxBL0mVM+glqXIGvSRVzqCXpMoZ9JJUOYNekipn0EtS5Qx6SapcW0EfER+NiCcj4omI+Fp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/Bp4A/hm4qubjD3yN1vWIM7TOzDdN5XgDf11eh2PAh6bTJmfGSlLlej10I0maYQa9JFXOoJekyhn0klQ5g16SKmfQS1LlDHpJqpxBL0mV+3+orRa1xwzUhAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = np.genfromtxt(\"H:\\code\\python\\Machine Learning\\Regression\\data.csv\",delimiter = \",\")\n",
    "x_data = data[:,0]\n",
    "y_data = data[:,1]\n",
    "plt.scatter(x_data,y_data)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#学习率learning rate\n",
    "lr = 0.0001\n",
    "#截距\n",
    "b = 0\n",
    "#斜率\n",
    "k = 0\n",
    "#最大迭代次数\n",
    "epochs = 50\n",
    "\n",
    "#最小二乘法\n",
    "def cost_function(b,k,x_data,y_data):\n",
    "    totalError = 0\n",
    "    for i in range(0,len(x_data)):\n",
    "        totalError += (y_data[i]-(k*x_data[i]+b))**2\n",
    "    return totalError/float(len(x_data))/2\n",
    "def gradient_descent_method(x_data,y_data,b,k,epochs):\n",
    "    #计算总数据量\n",
    "    m = float(len(x_data))\n",
    "    for i in range(epochs):\n",
    "        b_grad = 0\n",
    "        k_grad = 0\n",
    "        #计算梯度的总和再求平均\n",
    "        for j in range(0,len(x_data)):\n",
    "            b_grad = (1/m)*((k*x_data[j]+b)-y_data[j])\n",
    "            k_grad = (1/m)*((k*x_data[j]+b)-y_data[j])*x_data[j]\n",
    "        #更新b和k\n",
    "        b = b-(lr*b_grad)\n",
    "        k = k-(lr*k_grad)\n",
    "        #每迭代五次，输出一次图像\n",
    "#         if i %5==0:\n",
    "#             print(\"epochs:\",i)\n",
    "#             plt.plot(x_data,y_data,'b.')\n",
    "#             plt.plot(x_data,k*x_data+b,'r.')\n",
    "#             plt.show()\n",
    "    return b,k\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting b=0,k=0,cost=171354.91568831136\n",
      "Running...\n",
      "After50 iterations b=0.0020803244148597053,k=1.200072584551289,cost= 76451.47830416965\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAFfJJREFUeJzt3X+QXeV93/H31xKLi1NbP5AZLMkVrtUk1DQx3SGsnbYbb2oDZSJqYIrjRhqimXVnoCE/pjFq/mBad0bBzZjE+cFEY7BRTCEu0KBxSYCRtZO2cyFe2R4Mlh0WcNECsdYGk0xoEJK//eM8ay6r1a6099fuOe/XzM655znP1X3OPVfnc85zfkVmIklqnjcNugGSpMEwACSpoQwASWooA0CSGsoAkKSGMgAkqaEMAElqKANAkhrKAJCkhlo96AYs5Oyzz84tW7YMuhmStKIcPHjwu5m5YbF6yzoAtmzZwuTk5KCbIUkrSkT831OpZxeQJDWUASBJDWUASFJDGQCS1FAGgCQ11KIBEBG3R8SRiHi8rey/RsQ3I+KxiPgfEbGmbdquiJiKiG9FxIfayi8pZVMRcWP3Z0WSdDpOZQ/gc8Alc8oeBt6Tmf8E+EtgF0BEnA9cA/zj8p4/iIhVEbEK+H3gUuB84COlriRprlYLdu+uhj206HUAmfnnEbFlTtlDbaOPAFeV19uAuzPzVeCZiJgCLirTpjLzaYCIuLvU/UZHrZekumm1YGwMjh6FoSHYvx9GRnryUd04BvCLwJ+W1xuBw23TpkvZycpPEBHjETEZEZMzMzNdaJ4krSATE9XK//jxajgx0bOP6igAIuI3gGPAnbNF81TLBcpPLMzck5nDmTm8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RW7BZiZfwUcjogfLUVjwDdoyPKn6vq5OCLOKv8XZue/Ecu/zeku7weBD0bE2rIX9cFSdvoGfUBkgQMll1HdOfQp4DcG3Z4ezeNPU+26PQZ8rfxdRtWvuR94sgzXlfpBdXbUU8DXqc6eGPh8dOm7GAW+WF6/C/gLYAr478CZpfzNZXyqTH/XoNvdhfn+SWCy/Ab+BFjbpOUP/Cfgm8DjwB8BZ9Z5+QN3UR3veI1qS37nUpY38Ivle5gCrl1qe7wSWJIaarl2AUmSeswAkKSGMgAkqaEMAElqKANAkhrKAJCkhjIAJKmhDABJaqj/Dy7GqXwsJ6OoAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(\"Starting b={0},k={1},cost={2}\".format(b,k,cost_function(b,k,x_data,y_data)))\n",
    "print(\"Running...\")\n",
    "b,k = gradient_descent_method(x_data,y_data,b,k,epochs)\n",
    "print(\"After{0} iterations b={1},k={2},cost= {3}\".format(epochs,b,k,cost_function(b,k,x_data,y_data)))\n",
    "\n",
    "#画图\n",
    "plt.plot(x_data,y_data,'b.')\n",
    "plt.plot(x_data,k*x_data+b,'r.')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#sklearn库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "OSError",
     "evalue": "H:\\code\\python\\机器学习\\回归\\data.csv not found.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mOSError\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-7-502cfad454ec>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgenfromtxt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"H:\\code\\python\\机器学习\\回归\\data.csv\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mdelimiter\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\",\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mx_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0my_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mscatter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx_data\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my_data\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mH:\\anaconda\\lib\\site-packages\\numpy\\lib\\npyio.py\u001b[0m in \u001b[0;36mgenfromtxt\u001b[1;34m(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows, encoding)\u001b[0m\n\u001b[0;32m   1698\u001b[0m             \u001b[0mfname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1699\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbasestring\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1700\u001b[1;33m             \u001b[0mfhd\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0miter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_datasource\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'rt'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1701\u001b[0m             \u001b[0mown_fhd\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1702\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mH:\\anaconda\\lib\\site-packages\\numpy\\lib\\_datasource.py\u001b[0m in \u001b[0;36mopen\u001b[1;34m(path, mode, destpath, encoding, newline)\u001b[0m\n\u001b[0;32m    260\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    261\u001b[0m     \u001b[0mds\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mDataSource\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdestpath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 262\u001b[1;33m     \u001b[1;32mreturn\u001b[0m \u001b[0mds\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnewline\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnewline\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    263\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    264\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mH:\\anaconda\\lib\\site-packages\\numpy\\lib\\_datasource.py\u001b[0m in \u001b[0;36mopen\u001b[1;34m(self, path, mode, encoding, newline)\u001b[0m\n\u001b[0;32m    616\u001b[0m                                       encoding=encoding, newline=newline)\n\u001b[0;32m    617\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 618\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mIOError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"%s not found.\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mpath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    619\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    620\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mOSError\u001b[0m: H:\\code\\python\\机器学习\\回归\\data.csv not found."
     ]
    }
   ],
   "source": [
    "data = np.genfromtxt(\"H:\\code\\python\\机器学习\\回归\\data.csv\",delimiter = \",\")\n",
    "x_data = data[:,0]\n",
    "y_data = data[:,1]\n",
    "plt.scatter(x_data,y_data)\n",
    "plt.show()\n",
    "print(x_data.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(18, 1)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_data = data[:,0,np.newaxis] #np.newaxis 调整维度用的\n",
    "y_data = data[:,1,np.newaxis]\n",
    "print(x_data.shape)\n",
    "model = LinearRegression()\n",
    "model.fit(x_data,y_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAEthJREF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RU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x_data,y_data,'b.')#  b.表示颜色为蓝色\n",
    "plt.plot(x_data,model.predict(x_data),'r.')# r.表示颜色为红色\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
